import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    allmenus:[]
  },
  getters:{
    allmenus(state){
      var data=state.allmenus
      var rs={};
      for(let i=0;i<data.length;i++){
        var permission=data[i];
        if(permission.parentid==0){
          permission.children=[];
          rs[permission._id]=permission;
        }
      }
      for(let i=0 ;i<data.length;i++){
        var permission=data[i]
        for(var key in rs){
          if (permission.parentid == key){
            rs[key].children.push(permission)
          }
        }
      }
      return rs
    }
  },
  mutations: {
    ALLMENUS(state,payload){
      state.allmenus=payload
    }
  },
  actions: {
  },

})
